package com.niit.main;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.niit.entity.Student;
import com.niit.mapper.StudentMapper;
import com.niit.util.MybatisUtil;

/**
 * 
 * 根据班级名称和性别查询班级学生列表1-使用getMapper()方法获取Mapper(Dao)对象，然后调用Mapper接口(Dao接口)的方法实现查询
 *
 * @author hanliang
 */
public class Test07_getStudentsByBatchAndGender {

	public static void main(String[] args) {

		List<Student> list = null;
		String batchName = "22软件外包01班";
		String gender = "女";

		try (SqlSession session = MybatisUtil.openSession()) {
			// selectList()或selectOne()方法只接受一个查询参数，所以本程序需要换成getMapper()的方式执行语句
			// list=session.selectList("getStudentListByBatchAndGender1",batchName,gender);
			StudentMapper mapper = session.getMapper(StudentMapper.class);
			list = mapper.getStudentListByBatchAndGender1(batchName, gender);
		}

		System.out
				.println("-------------------------------------------------------------------------------------------");
		System.out.println("学号\t\t姓名\t\t密码\t\t性别\t班级");
		System.out
				.println("-------------------------------------------------------------------------------------------");

		for (Student s : list) {
			System.out.println(s);
		}
	}
}
